/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plures;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Guilherme
 */
public class VersionsArray extends HashMap<Integer,Integer>{
    
    private static final int        INITIAL_VERSION = 1;      

    public VersionsArray(){}
    
    public VersionsArray(VersionsArray va)
    {
        super.putAll(va);
    }    
    
    public boolean compare(VersionsArray va)
    {
        Integer i;
        for(Map.Entry<Integer,Integer> item : va.entrySet())
        {
            i = super.get(item.getKey());
            if(i == null)
            {
                return false;
            }
            if ((i != null) && (i < item.getValue()))
            {
                return false;
            }
            
        }
        return true;
    }
    
    public void update(int client)
    {
        Integer i = super.get(client);
        if(i == null)
        {
            super.put(client, INITIAL_VERSION);
        }
        else
        {
            super.put(client, super.get(client) + 1);
        }
    }
    
}
